package org.halo.trade.data.sina;


public class Level2 implements Comparable
{
	public String symbol;// 证券代码
	public String name;

	public double lastclose;  //最后收盘
	public double open;    //开盘
	public double high;    //最高
	public double low;     //最低

	public double price;// 最新 价格
	public double tradecount;// 成交笔数
	public double amount;// 成交额
	public long volume;// 成交量
	public long time;// 时间
	public int op;// // 方向

	// 买一价 买二价 买三价 买四价 买五价 卖一价 卖二价 卖三价 卖四价 卖五价
	// 买一量 买二量 买三量 买四量 买五量 卖一量 卖二量 卖三量 卖四量 卖五量

	public long[] askvol = new long[10];
	public double[] ask = new double[10];
	public long[] bidvol = new long[10];
	public double[] bid = new double[10];

	static public final int OP_BUY = 0;
	static public final int OP_SELL = 1;

	public double getSpread()
	{
		return (ask[0] - bid[0]);
	}

	public	double getSpreadRate()
	{
		if (bid[0] > 0)
		{
			return (ask[0] - bid[0]) / bid[0];
		}
		return Double.MAX_VALUE;
	}

	public void printSpreadInfo()
	{
		System.out.println(symbol + " " + name + " spread:" + Utils.doubleToString(getSpread(), 3) + " spreadRate:" + Utils.doubleToString(getSpreadRate() * 100, 3) + "%");
	}

	public void print()
	{
		System.out.println(Utils.msToStr(time));
		System.out.println(name + " " + symbol);
		System.out.println("开盘:" + open + " 昨收:" + lastclose);
		System.out.println("最低:" + low + " 最高:" + high);
		System.out.println("最新:" + price + " 量：" + volume + " 成交额:" + amount);
		System.out.println("spread:" + Utils.doubleToString(getSpread(), 3) + " spreadRate:" + Utils.doubleToString(getSpreadRate() * 100, 3) + "%");

		System.out.println("---------------------------");
		for (int i = ask.length; i > 0; i--)
		{
			System.out.println("卖" + (i) + "\t" + ask[i - 1] + "\t" + askvol[i - 1] / 100);
		}
		System.out.println("---------------------------");
		for (int i = 0; i < bid.length; i++)
		{
			System.out.println("买" + (i + 1) + "\t" + bid[i] + "\t" + bidvol[i] / 100);
		}
	}

	@Override
	public int compareTo(Object o)
	{
		Level2 other = (Level2) o;
		if (other == null)
			return 1;

		if (!symbol.equals(other.symbol))
			return 1;

		if (lastclose != other.lastclose)
			return 1;

		if (open != other.open)
			return 1;
		if (high != other.high)
			return 1;
		if (low != other.low)
			return 1;

		if (op != other.op)
			return 1;

		if (price != other.price)
			return 1;

		if (!ask.equals(other.ask))
			return 1;

		if (!askvol.equals(other.askvol))
			return 1;

		if (!bid.equals(other.bid))
			return 1;

		if (!bidvol.equals(other.bidvol))
			return 1;

		// TODO Auto-generated method stub
		return 0;
	}

}
